/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package UCM;

import Source.CreateManager;
import Views.ViewCreateManager;

/**
 *
 * @author Joshua King
 */
public class UCCreateManager implements UCController {

    private ViewCreateManager view;
    private CreateManager model = new CreateManager();
    
    public UCCreateManager(ViewCreateManager view) {
        this.view = view;
        view.loadTo(model);
    }
    
    /**
Precondition: The admin is logged in and view create manager.

   1. Admin enters details than clicks create manager.
   2. System loads data to the model.
   3. System confirm the validity of the information.
   4. System commits data.
   5. System refreshes the create flight UI indicating success. 

Postcondition: A new flight has been created and success shown.

Unsuccessful Outcome:

    * 3a) The details entered by the manager are inappropriate.
         1. System refreshes the UI and explains errors to the manager. 
    * 4a) System can't commit data.
         1. System updates the UI informing the manager that the service is currently unavailable. 
    * 4b) System receives notice that an error has occurred.
         1. System updates the UI informing the manager that there was an internal error. 
     */
    public void run() {
       //2. System loads data to the model.
        view.loadData();
        //3. System confirm the validity of the information.
        if (model.checkValidity()) {
            //4. System commits data.
            if (model.commitData()) {
                //5. System refreshes the create flight UI indicating success.
                view.updateSuccess();
            } else {
               // * 4a) System can't commit data.
               // 1. System updates the UI informing the manager that the service is currently unavailable. 
               // * 4b) System receives notice that an error has occurred.
               // 1. System updates the UI informing the manager that there was an internal error.
                view.updateFailure();
            }
        } else {
            //* 3a) The details entered by the manager are inappropriate.
            //1. System refreshes the UI and explains errors to the manager. 
            view.updateFailure();
        }
    }

}
